package com.narbeshuber.tablet.lasalara;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

import android.app.AlertDialog;
import android.content.Context;
import android.net.ConnectivityManager;
import android.util.Log;
import android.widget.TextView;

public class Utils {
	public static LasaLaraActivity lasalaraActivity;
	private static int textSize = 18;
	
	public static int getTextSize(){
		return textSize;
	}
	
	public static void increaseTextSize(){
		textSize+=1;
		TextView question = (TextView)lasalaraActivity.findViewById(R.id.question);
		TextView answer = (TextView)lasalaraActivity.findViewById(R.id.answer);
		question.setTextSize(textSize);
		answer.setTextSize(textSize);
	}
	
	public static void decreaseTextSize(){
		textSize-=1;
		TextView question = (TextView)lasalaraActivity.findViewById(R.id.question);
		TextView answer = (TextView)lasalaraActivity.findViewById(R.id.answer);
		question.setTextSize(textSize);
		answer.setTextSize(textSize);
	}

	public static boolean emailValidation(String email) {
		String expression = "^[\\w\\-]?([\\.\\w]?)+[\\w]+@([\\w\\-]+\\.)+[A-Z]{2,4}$";
		CharSequence inputStr = email;
		Pattern pattern = Pattern.compile(expression, Pattern.CASE_INSENSITIVE);
		Matcher matcher = pattern.matcher(inputStr);
		return matcher.matches();
	}

	public static boolean isOnline(Context context) {
		try {
			ConnectivityManager manager = (ConnectivityManager) context
					.getSystemService(Context.CONNECTIVITY_SERVICE);
			if (manager.getActiveNetworkInfo() != null
					&& manager.getActiveNetworkInfo().isConnected()){
				return true;
			}
		} catch (Exception e) {
			Log.d("bitch u have a trouble", e.toString());
		}
		new AlertDialog.Builder(context)
				.setTitle("You are offline.")
				.setMessage(
						"To login, or to open a book or chapter for the first time, you need an Internet connection.")
				.setPositiveButton("OK", null).show();
		return false;
	}

}
